home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Processes / Launch Me / LaunchMe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-15  |  2.8 KB  |  82 lines  |  [TEXT/CWIE]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Routines demonstrating how to launch an application without a currently
  5. **    running application to actually call LaunchApplication().
  6. **
  7. **    by Mark Cookson, Apple Developer Technical Support
  8. **
  9. **    File:    LaunchMe.c
  10. **
  11. **    Copyright ©1996 Apple Computer, Inc.
  12. **    All rights reserved.
  13. **
  14. **    You may incorporate this sample code into your applications without
  15. **    restriction, though the sample code has been provided "AS IS" and the
  16. **    responsibility for its operation is 100% yours.  However, what you are
  17. **    not permitted to do is to redistribute the source as "Apple Sample
  18. **    Code" after having made changes. If you're going to re-distribute the
  19. **    source, we require that you make it clear in the source that the code
  20. **    was descended from Apple Sample Code, but that you've made changes.
  21. */
  22.  
  23. #include "LaunchMe.h"
  24.  
  25. static void ToolBoxInit (void)
  26. {    
  27.     MaxApplZone();
  28.     MoreMasters ();
  29.     InitGraf (&qd.thePort);
  30.     InitFonts ();
  31.     InitWindows ();
  32.     InitMenus ();
  33.     TEInit ();
  34.     InitDialogs ((long)nil);
  35.     InitCursor ();
  36.     return;
  37. }
  38.  
  39. void main (void)
  40. {
  41.     MyDelayedLaunchPtr        timeRecPtr;
  42.     Handle                    NotificationRtnHandle;
  43.     SFTypeList                sfType        = {'APPL', nil, nil, nil};
  44.     THz                        ourZone;
  45.  
  46.     ToolBoxInit ();
  47.  
  48.     timeRecPtr                = (MyDelayedLaunchPtr)NewPtrSys (sizeof (MyDelayedLaunchRec));    // Put our variables in the system heap
  49.     if (timeRecPtr == nil)                                            // We are SO out of memory!
  50.         return;                                                        // memFullErr if this was a real function
  51.  
  52.     ourZone                    = GetZone();
  53.     SetZone(SystemZone());                                            // Switch to system heap so GetResource loads the resource into the system heap
  54.     NotificationRtnHandle    = GetResource ('rsrc', 0);                // Get our code resource that does the real work
  55.     if (NotificationRtnHandle == nil || ResError ()) {                // We are out of memory
  56.         DisposePtr ((Ptr)timeRecPtr);
  57.         return;                                                        // memFullErr if this was a real function
  58.     }
  59.  
  60.     HLock(NotificationRtnHandle);                                    // Don't nobody go nowhere
  61.     DetachResource(NotificationRtnHandle);
  62.     SetZone(ourZone);
  63.  
  64.     StandardGetFile (nil, 1, sfType, &timeRecPtr->theSFReply);        // Prompt for app to launch
  65.     if (timeRecPtr->theSFReply.sfGood != true) {                    // User doesn't want to launch
  66.         DisposePtr ((Ptr)timeRecPtr);
  67.         DisposeHandle (NotificationRtnHandle);
  68.         return;                                                        // userCanceledErr is this was a real function
  69.     }
  70.  
  71.     timeRecPtr->launchMe.launchAppSpec            = &timeRecPtr->theSFReply.sfFile;
  72.     timeRecPtr->launchMe.launchBlockID            = extendedBlock;
  73.     timeRecPtr->launchMe.launchEPBLength        = extendedBlockLen;
  74.     timeRecPtr->launchMe.launchFileFlags        = nil;
  75.     timeRecPtr->launchMe.launchControlFlags        = launchContinue + launchNoFileFlags;
  76.     timeRecPtr->launchMe.launchAppParameters    = nil;
  77.  
  78.     timeRecPtr->theTask.tmAddr                    = (void *)*NotificationRtnHandle;
  79.     timeRecPtr->theTask.tmWakeUp                = 0;
  80.     InsXTime ((QElemPtr)timeRecPtr);
  81.     PrimeTime ((QElemPtr)timeRecPtr, kDelay);
  82. }